﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>数据同步接口界面</title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css" />
    <style type="text/css">
        .container
        {
            text-align: center;
            clear: both;
            width: 100%;
            height: auto;
            margin-top:10px;
            
        }
        .container-fluid
        {
            margin-top:10px;
            }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
        	<div class="col-md-6">
                <form class="form-inline">
                    <div class="form-group">
                        <label class="sr-only">人才网企业名称</label>
                        <p class="form-control-static">人才网企业名称</p>
                    </div>
                    <div class="form-group">
                        <label for="key" class="sr-only">请输入企业名...</label>
                        <input type="text" class="form-control input-sm" id="key" placeholder="请输入企业名..." />
                    </div>
                    <button type="button" class="btn btn-info btn-sm" onclick="search()">查找</button>
                </form>

                    <div id="datagrid" class="mini-datagrid" virtualscroll="true" allowresize="false"
                         style="width: 550px; height: 250px;" url="../data/datasync.aspx?method=searchCompanysFromHzhr">
                        <div property="columns">
                            <!--<div type="indexcolumn">
                </div>-->
                            <div field="cu_no" width="60" headeralign="center" allowsort="true">
                                企业编号
                            </div>
                            <div field="cu_name" width="150" headeralign="center" allowsort="true">
                                企业名称
                            </div>
                            <div field="cu_address" width="200" headeralign="center" allowsort="true">
                                企业地址
                            </div>
                            <div field="cu_contact" width="100" headeralign="center" allowsort="true">
                                联系人
                            </div>
                            <div field="cu_tel" width="100" headeralign="center" allowsort="true">
                                电话
                            </div>
                            <!--<div field="cu_fax" width="200" headeralign="center" allowsort="true">
                    传真</div>
                <div field="cu_email" width="250" headeralign="center" allowsort="true">
                    邮件</div>
                <div field="cu_url" width="100" headeralign="center" allowsort="true">
                    网址</div>
                <div field="cu_postcode" width="100" headeralign="center" allowsort="true">
                    邮编</div>-->
                            <div field="cu_introduce" width="250" headeralign="center" allowsort="true">
                                企业简介
                            </div>
                            <!-- <div field="cu_trade" width="100" headeralign="center" allowsort="true">
                    企业所属行业</div>
                <div field="cu_property" width="200" headeralign="center" allowsort="true">
                    企业性质</div>
                <div field="cu_area" width="100" headeralign="center" allowsort="true">
                    所在地区</div>
                <div field="cu_modifytime" width="100" headeralign="center" allowsort="true">
                    修改时间</div>-->
                        </div>
                    </div>
               </div>
        <div class="col-md-6">
            <form class="form-inline">
                <div class="form-group">
                    <label class="sr-only">供需系统企业名称</label>
                    <p class="form-control-static">供需系统企业名称</p>
                </div>
                <div class="form-group">
                    <label for="tzswKey" class="sr-only">请输入企业名...</label>
                    <input type="text" class="form-control input-sm" id="tzswKey" placeholder="请输入企业名..." />
                </div>
                <button type="button" class="btn btn-info btn-sm" onclick="searchSyncCompany()">查找</button>
            </form>
                <div id="datagrid1" class="mini-datagrid" virtualscroll="true" allowresize="false"
                    style="width: 550px; height: 250px;" url="../data/datasync.aspx?method=searchCompanysFromTzys">
                    <div property="columns">
                        <!--<div type="indexcolumn">
                </div>-->
                        <div field="businessuser_id" width="60" headeralign="center" allowsort="true">
                            企业编号</div>
                        <div field="company" width="150" headeralign="center" allowsort="true">
                            企业名称</div>
                        <div field="address" width="200" headeralign="center" allowsort="true">
                            企业地址</div>
                        <div field="contacts" width="100" headeralign="center" allowsort="true">
                            联系人</div>
                        <div field="contactphone" width="250" headeralign="center" allowsort="true">
                            联系人手机</div>
                        <div field="businessprofile" width="100" headeralign="center" allowsort="true">
                            业务简介</div>
                        <div field="companyproperty" width="200" headeralign="center" allowsort="true">
                            企业性质</div>
                        <div field="corporatename" width="100" headeralign="center" allowsort="true">
                            法人姓名</div>
                        <div field="createtime" width="100" headeralign="center" allowsort="true">
                            创建时间
                        </div>
                        <div field="email" width="200" headeralign="center" allowsort="true">
                            电子邮箱</div>
                        <div field="faxphone" width="250" headeralign="center" allowsort="true">
                            传真电话</div>
                        <div field="industry" width="100" headeralign="center" allowsort="true">
                            行业（临时）</div>
                        <div field="modifiedtime" width="100" headeralign="center" allowsort="true">
                            修改时间</div>
                        <div field="website" width="200" headeralign="center" allowsort="true">
                            公司网址</div>
                        <div field="zipcode" width="250" headeralign="center" allowsort="true">
                            邮政编码</div>
                        <div field="featuredindustry" width="100" headeralign="center" allowsort="true">
                            特色产业</div>
                        <div field="region" width="100" headeralign="center" allowsort="true">
                            所在地区</div>
                        <div field="socialsecurity" width="100" headeralign="center" allowsort="true">
                            社会保障编号</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <table style="text-align: center;">
            <tr>
                <td>
                    <button class="btn btn-primary" id="btnSyncStart" onclick="addSyncInfo()">
                        关联企业
                    </button>
                </td>
                <td>&nbsp;&nbsp;</td>
                <td>
                    <button class="btn btn-primary" id="addNew" onclick="window.open('http://www.hzhr.com/web/Company/Register.html')">
                        新增企业
                    </button>
                </td>
                <td>&nbsp;&nbsp;</td>
                <td>
                    <button class="btn btn-warning" id="btnImportStart" onclick="importSyncInfo()">
                        导入企业
                    </button>
                </td>
                <td>&nbsp;&nbsp;</td>
                <td>
                    <button class="btn btn-danger" id="importCompanys" onclick="importCompanys()">
                        批量导入企业
                    </button>
                </td>
            </tr>
        </table>
    </div>
    <div class="container-fluid">
        <div id="SyncCompanys" class="mini-datagrid" virtualscroll="true" allowresize="false"
            style="width: 100%; height: 250px;" url="../data/datasync.aspx?method=showSyncCompanys">
            <div property="columns">
                <!--<div type="indexcolumn">
                </div>-->
                <div field="sc_company_id" width="60" headeralign="center" allowsort="true">
                    企业编号</div>
                <div field="sc_business_id" width="50" headeralign="center" allowsort="true">
                    关联企业编号</div>
                <div field="cu_name" width="150" headeralign="center" allowsort="true">
                    企业名称</div>
                <div field="cu_address" width="200" headeralign="center" allowsort="true">
                    企业地址</div>
                <div field="cu_contact" width="100" headeralign="center" allowsort="true">
                    联系人</div>
                <div field="cu_tel" width="100" headeralign="center" allowsort="true">
                    电话</div>
                <div field="cu_fax" width="200" headeralign="center" allowsort="true">
                    传真</div>
                <div field="cu_email" width="250" headeralign="center" allowsort="true">
                    邮件</div>
                <div field="cu_url" width="100" headeralign="center" allowsort="true">
                    网址</div>
                <div field="cu_postcode" width="100" headeralign="center" allowsort="true">
                    邮编</div>
                <div field="cu_introduce" width="250" headeralign="center" allowsort="true">
                    企业简介</div>
                <div field="cu_trade" width="100" headeralign="center" allowsort="true">
                    企业所属行业</div>
                <div field="cu_property" width="200" headeralign="center" allowsort="true">
                    企业性质</div>
                <div field="cu_area" width="100" headeralign="center" allowsort="true">
                    所在地区</div>
                <div field="cu_modifytime" width="100" headeralign="center" allowsort="true">
                    修改时间</div>
            </div>
        </div>
    </div>

</body>
<script type="text/javascript">
    mini.parse();
    var grid = mini.get("datagrid");
    var grid1 = mini.get("datagrid1");
    var SyncCompanyGird = mini.get("SyncCompanys");
    grid.load();
    grid1.load();
    SyncCompanyGird.load();

    $("#btnImportStart").hide();
    $("#importCompanys").hide();


    //手动匹配企业同步信息
    function addSyncInfo() {

        if (null == grid.getSelected() || null == grid1.getSelected()) {
            mini.alert("未进行企业选择，请进行选择", "Warning!");
        } else {
            var itemHzhr = grid.getSelected();
            var itemSync = grid1.getSelected();

            mini.confirm("确定关联此条记录？", "确定？",
            function (action) {
                if (action == "ok") {

                    //itemHzhr.sc_company_id = itemHzhr.cu_no;
                    itemHzhr.sc_business_id = itemSync.businessuser_id;

                    var json = mini.encode(itemHzhr);
                    $.ajax({
                        url: "../data/datasync.aspx?method=insertCompany",
                        type: "post",
                        data: { data: json },
                        success: function (text) {
                            if (-1 != text) {
                                mini.alert("企业关联成功", "成功!");
                                grid.reload();
                                grid1.reload();
                                SyncCompanyGird.reload();
                            } else if (-1 == text) {
                                mini.alert("关联失败，请重试！", "失败!");
                            }
                            //grid.reload();
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            alert("操作异常：" + textStatus);
                        }
                    });
                } else {
                    return;
                }
            }
        );
        }
    }
    //导入企业
    function importSyncInfo() {
        if (null == grid1.getSelected()) {
            mini.alert("请先选择一家关联企业！", "Warning!");
            return;
        } else {
            var data = grid1.getSelected();
            var json = mini.encode(data);
            //var syncCompanyInfo = json.businessuser_id;
        }
        grid1.loading("保存中，请稍后......");
        mini.confirm("确认导入此企业记录？此过程不可逆！", "确定？",
                function (action) {
                    if (action == "ok") {
                        $.ajax({
                            url: "../data/datasync.aspx?method=importSingleCompany",
                            type: "post",
                            data: { data: json },
                            success: function (text) {
                                if (text != -1) {
                                    mini.alert("操作成功！");
                                    grid.reload();
                                    grid1.reload();
                                    SyncCompanyGird.reload();
                                }
                                else if (text == -1) {
                                    mini.alert("操作失败！");
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                mini.alert("error");
                            }
                        });
                    }
                }
            );
    }
    

    //导入剩余未同步企业
    function importCompanys() {
        var data = grid1.getData();
        var json = mini.encode(data);
        grid1.loading("保存中，请稍后......");
        mini.confirm("确认已无重复企业？此过程不可逆！", "确定？",
                function (action) {
                    if (action == "ok") {
                        $.ajax({
                            url: "../data/datasync.aspx?method=importCompanys",
                            type: "post",
                            data: { data: json },
                            success: function (text) {
                                if (text != -1) {
                                    mini.alert("操作成功！");
                                    grid.reload();
                                    grid1.reload();
                                    SyncCompanyGird.reload();
                                }
                                else if (text == -1) {
                                    mini.alert("操作失败！");
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                mini.alert("error");
                            }
                        });
                    }
                }
            );
    }


    //function saveData() {

    //    var data = SyncCompanyGird.getData();
    //    var json = mini.encode(data);
    //    document.write(json);
    //    grid.loading("同步中，请稍后......");
    //    $.ajax({
    //        url: "../data/datasync.aspx?method=syncCompanys",
    //        data: { data: json },
    //        type: "post",
    //        success: function (text) {
    //            grid.reload();
    //        },
    //        error: function (jqXHR, textStatus, errorThrown) {
    //            alert(jqXHR.responseText);
    //        }
    //    });
    //}

   

    function search() {
        var key = document.getElementById("key").value;
        grid.load({ key: key });
    }
    
    
    function searchSyncCompany() {
        var tzswKey = document.getElementById("tzswKey").value;
        grid1.load({ key: tzswKey });
    }
</script>
</html>
